import request from '@/utils/request'

export default {
  getUserList(searchModel) {
    let params = '&pageNo=' + searchModel.pageNo + '&pageSize=' + searchModel.pageSize
    params =
      searchModel.username === '' ||
      searchModel.username === null ||
      searchModel.username === undefined
        ? params
        : params + '&username=' + searchModel.username
    params =
      searchModel.phone === '' ||
      searchModel.phone === null ||
      searchModel.phone === undefined
        ? params
        : params + '&phone=' + searchModel.phone
    return request({
      url: '/user/list?' + params,
      method: 'get'

      // params:{
      //   pageNo:searchModel.pageNo,
      //   pageSize:searchModel.pageSize,
      //   username:searchModel.username,
      //   phone:searchModel.phone
      // }
    })
  },
  addUser(user) {
    return request({
      url: '/user/addUser',
      method: 'post',
      data: user
    })
  },
  updateUser(user) {
    return request({
      url: '/user/updateUser',
      // method: 'put',
      method: 'post',
      data: user
    })
  },
  saveUser(user) {
    if (user.userId == null || user.userId === undefined) {
      return this.addUser(user)
    }
    return this.updateUser(user)
  },
  getUserById(userId) {
    return request({
      // url: '/user/'+id,
      url: `/user/getUserById/${userId}`,
      method: 'get'
    })
  },
  deleteById(userId) {
    return request({
      url: `/user/deleteUserById`,
      method: 'delete',
      params: {
        deleteUserId: userId
      }
    })
  },
  checkUsernameCount(username) {
    let params = ''
    params =
      username === '' ||
      username === null ||
      username === undefined
        ? params
        : params + 'username=' + username
    return request({
      url: '/user/checkname?' + params,
      method: 'get'
    })
  },
  checkPassword(userId, password) {
    let params = ''
    params =
      userId === '' ||
      userId === null ||
      userId === undefined
        ? params
        : params + 'userId=' + userId
    params =
      password === '' ||
      password === null ||
      password === undefined
        ? params
        : params + '&password=' + password
    return request({
      url: '/user/checkpassword?' + params,
      method: 'get'
    })
  }

}
